<%--
  Created by IntelliJ IDEA.
  User: YANG
  Date: 2019/11/12
  Time: 22:40
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>招聘详情界面</title>
    <script  src="Js/jquery-3.4.1.min.js" ></script>
    <script src="Js/jquery-ui.js"></script>
    <script src="Js/jquerysession.js"></script>
    <link href="Css/layout.css" rel="stylesheet">
    <link href="Css/header.css" rel="stylesheet">
    <link href="Css/jobdetail.css" rel="stylesheet">
    <style>
        .demo{
            position:relative;
            font-size: 18px;
            color: #222222;
            margin-top: 10px;
            width: 100%;
            height: 40px;
            background-color:#6699CC;

        }
        .jobtiltle{
            width:260px;
            line-height:30px;
            background-color: #6699cc;
            color: white;
            font-size: 14px;
            margin-left: 15px;


        }
        .jobtiltle span{
            margin-left:20px;
        }
        .demo span{
            display: inline-block;
            width:60px;
            line-height:40px;
            margin-left: 20px;
        }

        .demoin2{
            font-size: 12px;
            color: #222222;
            position:absolute;
            top:0;
            left:0;
            right:0;
            bottom:0;
            width: 100%;
            height:40px;
            margin:auto;
            vertical-align: middle
        }
        button{
            margin-left: 20px;
            width: 80px;
            background-color: #868686;
            border: 0;
        }
    </style>
</head>

<body>
<script>
    var jobid=<%=request.getParameter("JobID")%>
    $.ajax({
        type:"GET",
        url:"getJobAndCompanyByJobID.action?JobID="+jobid,
        dataType:"json",
        success:function (res) {
        //    在这里把所有数据都替换
            var companyIdentity;
            if(res.company.CompanyIdentified==1){
                companyIdentity='已认证'
            }else{
                companyIdentity='未认证'
            }
            $("#JobName").html(res.job.JobName);
            $("#JobSalary").html(res.job.JobSalary+"/月")
            $("#CompanyName").html(res.company.CompanyName);
            //取数据应该没问题了，现在看如果有错误应该是赋值函数有问题
            $("#JobInfo").html("工作地点&nbsp;"+res.job.JobAddress+"&nbsp;&nbsp;|&nbsp;&nbsp;人数&nbsp;"+res.job.JobNum+"&nbsp;&nbsp;|&nbsp;&nbsp;发布时间&nbsp;"+res.job.PublishTime);
            $("#JobDuty").html(res.job.JobDuty);
            $("#JobRequire").html(res.job.JobRequire);
            $("#CompanyInfo").html(res.company.CompanyName+"&nbsp;&nbsp;|&nbsp;&nbsp;"+res.company.CompanyAddress+"&nbsp;&nbsp;|&nbsp;&nbsp;"+companyIdentity+"&nbsp;&nbsp;|邮箱&nbsp;"+res.company.CompanyEmail+"  |&nbsp;&nbsp;联系方式&nbsp;"+res.company.CompanyTelphone);
            $("#CompanyDetail").html(res.company.CompanyIntroduce)
            for(var j=res.other.length-1;j>=0;j--){
                console.log(res);
                $(".otherjob-detail").prepend(
                    '<div class="demo"><div class="demoin2" ><span>'+res.other[j].jobName+'</span>' +
                    '<span>'+res.other[j].jobSalary+'/月'+'</span>'+
                    '<span>'+res.other[j].jobAddress+'</span>'+
                    '</div></div>'
                )
            }
            },
        error:function () {

        }
    })

</script>
<%--顶部是轮播图，广告--%>

<%--  js操作写在这里--%>
<script>
    $(function() {
        try{
            //如何解决空指针报错呢？
            var UserName = "<%=session.getAttribute("UserName").toString()%>";
            var UserKind = "<%=session.getAttribute("UserKind").toString()%>";
            if (UserName!="") {
                //这里如果登录成功就需要把登录注册替换成一个用户头像和用户呢?
                //替换头像
                $("#aindex").replaceWith("<img src='Image/user.png' " +
                    "style='display:inline-block;width:32px;height:20px;margin:5px 10px 5px 10px'/>");
                //替换昵称
                $("#aregis").replaceWith("<a class='aregis'><%=session.getAttribute("UserName").toString()%></a>")
                //这里需要把用户头像更改掉，先不改动，然后我们先修改一下俩个操作按钮
                $(".maindiv").hide()
            }

        }catch (e) {
            return;
        }
    })

    function myresume() {
    //首先要弹出选择对话框

        $("#dialog1").show();
        $("#dialog1 select").empty();
        //不能多次点击
        //点击投递时应该需要知道当前用户是否导入了额外的简历，UserID,加载用户,如果有需要把简历的名称取出来
        $.ajax({
            type:"GET",
            url:"UserResume.action?UserID="+<%=session.getAttribute("UserID")%>,
            dataType:"json",
            success:function (res) {
                //在这里存储额外简历的名字
                $.session.set("resumename",res.extraresume.extraresume);
                if(res.extraresume.extraresume!="-1"){
                    $("#resumekind").append("<option value=1>默认简历</option><option value=2>已导入简历</option>");
                }else{
                    $("#resumekind").append("<option value=1>默认简历</option>");
                }
            },
            error:function () {
                
            }
            
        })


   }
   function submitresume() {
        //两个参数都要用，根据用户选择赋值
       var jobid=<%=request.getParameter("JobID")%>
       var resumekind =$('#resumekind option:selected').val();
       var resumeAddress;
       if(resumekind==1){
       //用户选择默认简历，
        resumeAddress="null";
       }else{
        resumeAddress=$.session.get("resumename");
       }

       $.ajax({
           type:"POST",
           url:"UserApply.action",
           data:{
               JobID:jobid,
               ResumeKind:resumekind,
               ResumeAddress:resumeAddress},
           dataType:"json",
           success:function (res) {
               if(res.json.result=="1"){

                   alert("申请成功!")
               }else if(res.json.result=="-1"){
                   alert("您已经申请过该职位!")
               }else{
                   alert("申请失败，稍后再试!")
               }
           },
           error:function () {
               
           }
       })
   //   首先要获得当前用户选择的简历类型，如果是默认简历，则存储的时候存0，地址不填，如果自定义，先要存储
   }
   function hideresume() {

       $("#dialog1").hide();
   }


</script>

<body>
<%--  界面写在这里--%>
<div class="header">
    <div class="in">
        <p class="call">商务合作联系&nbsp;110</p>
        <div class="login">
            <a  id="aindex" href="index.jsp" class="aindex">登录</a>
            <a id="aregis" href="register.jsp" class="aregis">注册</a>
        </div>
        <p class="welcome">医伯乐招聘网站欢迎您&nbsp;</p>
    </div>
</div>

<div id="topbar" class="topbar">
    <div class="in">
        <a href="" class="logo">
            <img src="/Image/bole.png"></img>
        </a>
        <div class="nav">
            <a href="main.jsp">首页</a>
            <a href="news.jsp">资讯</a>
            <a href="<%=session.getAttribute("UserKind")%>">我的</a>
        </div>
    </div>
</div>

<div class="bannnercontent">
<%--这个轮播图上面有两部分组成，第一部分是图片，第二部分是广告链接--%>
    <div class="in">
      <div class="banner">
          <a><img src="Image/banner.jpg"></a>
      </div>
      <div class="advise">
          <a>数据分析的第一堂课，低价秒杀中!</a><br>
          <a>放HR鸽子是一种什么感觉?</a><br>
          <a>到底是什么阻碍你成功跳槽?</a><br>
          <a>简历到底要不要放照片?</a><br>
      </div>
    </div>
</div>
<%--content上，是发布这个招聘信息的公司的一些信息--%>
<div class="content-top">
    <div class="in">
        <div class="jobinfo">
            <h1 id="JobName"></h1>
            <strong id="JobSalary"></strong><br><br>
            <a id="CompanyName"></a><br><br>
            <p id="JobInfo"></p>
        </div>
        <div class="jobapply">
            <button onclick="myresume()"><img src="Image/submit.png"/>&nbsp;&nbsp;投递简历</button>
        </div>
    </div>
</div>
<%--conten中，是这个招聘的详细信息--%>
<div class="content-center">
    <div class="in">
       <div class="jobdetail">
           <div class="pagetitle">工作职责</div>
           <div id="JobDuty" class="page"></div>
           <div class="pagetitle">应聘要求</div>
           <div id="JobRequire" class="page"></div>
           <div class="cominfo">
               <h1>公司信息</h1><br><br>
               <p id="CompanyInfo"></p>
           </div>
           <div id="CompanyDetail" class="page"></div>
       </div>

       <div class="otherjob">
           <div id="dialog1" style="background-color:#6699cc;display: none;width: 260px;margin-left: 15px; " >
               <form action="">
                   选择简历:<select id="resumekind">
               </select>
                   <input type="button" onclick="submitresume()" value="确定">
                   <input type="button" onclick="hideresume()" value="取消">
               </form>
           </div>
           <div class="jobtiltle">
               <span>职位名称</span><span>薪资待遇</span><span>工作地点</span>
           </div>
           <div class="otherjob-detail">
           </div>

       </div>
    </div>
</div>

<div class="footer">
    <div class="in">
        <div class="nag">
            <div class="e e_first">
                <label>销售热线：</label>
                123-456-789<br>
                <label>客服热线：</label>
                110-119-120<br>
                <label>Email：</label>
                10000@qq.com
            </div>
            <div class="e">
                <p class="tie">
                            <span class="e_icon">
                                <a href="">简介</a>
                            </span>
                </p><br>
                <a href="">
                    <span class="at">关于我们</span><em>(1000)</em>
                </a><br>
                <a href="">
                    <span class="at">服务声明</span><em>(1000)</em>
                </a><br>
                <a href="">
                    <span class="at">媒体报道</span><em>(1000)</em>
                </a>

            </div>
            <div class="e">
                <p class="tie">
                            <span class="e_icon">
                                <a href="">合作</a>
                            </span>
                </p><br>
                <a href="">
                    <span class="at">加入我们</span><em>(1000)</em>
                </a><br>
                <a href="">
                    <span class="at">联系我们</span><em>(1000)</em>
                </a><br>
                <a href="">
                    <span class="at">友情链接</span><em>(1000)</em>
                </a>
            </div>
            <div class="e">
                <p class="tie">
                            <span class="e_icon">
                                <a href="">帮助</a>
                            </span>
                </p><br>
                <a href="">
                    <span class="at">帮助中心</span><em>(1000)</em>
                </a><br>
                <a href="">
                    <span class="at">常见问题</span><em>(1000)</em>
                </a><br>
                <a href="">
                    <span class="at">新手引导</span><em>(1000)</em>
                </a>
            </div>
            <div class="e">
                <p class="tie">
                            <span class="e_icon">
                                <a href="">导航</a>
                            </span>
                </p><br>
                <a href="">
                    <span class="at">网站地图</span><em>(1000)</em>
                </a><br>
                <a href="">
                    <span class="at">职位搜索</span><em>(1000)</em>
                </a><br>
                <a href="">
                    <span class="at">简历中心</span><em>(1000)</em>
                </a>
            </div>
        </div>
    </div>
</div>
</body>
</html>
